﻿var comswing = new Comswing();

function Comswing() {
    var selfComswing = this;

    selfComswing.Date = function (date) {
        return moment(date).format('ll')
    }

    selfComswing.DateTime = function (date) {
        return moment(date).format('lll')
    }

    selfComswing.Message = function (message, messageType) {
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-top-full-width",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1100",
            "timeOut": "11000",
            "extendedTimeOut": "1100",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        }

        switch (messageType) {
            case 0: toastr.success(message);
                break;
            case 1: toastr.warning(message);
                break;
            case 2: toastr.error(message);
                break;
            case 3: toastr.info(message);
                break;
        }
    }

    selfComswing.ShowLoading = function () {
        $("input").attr("disabled", "disabled");
        $("select").attr("disabled", "disabled");
        $("button").attr("disabled", "disabled");

        toastr.options = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-top-full-width",
            "onclick": "",
            "timeOut": "0",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        }

        toastr.info("Loading...");
    }

    selfComswing.HideLoading = function (callback) {
        $("input").removeAttr("disabled");
        $("select").removeAttr("disabled");
        $("button").removeAttr("disabled");

        $.when(toastr.clear()).done(function () {
            if (callback)
                setTimeout(callback, 1200);
        });
    }

    selfComswing.HelpPopup = function (message, messageType) {
        var title = "Advice";
        if (adviceText)
            title = adviceText;

        switch (messageType) {
            case 0: toastr.success(message);
                break;
            case 1:
                $.magnificPopup.open({
                    items: {
                        src:
                            '<div class="panel panel-warning help-popup">' +
                                '<div class="panel-heading">' +
                                    '<h3 class="panel-title"><span class="glyphicon glyphicon-comment"></span> ' + title + '</h3>' +
                                '</div>' +
                                '<div class="panel-body">' +
                                    message +
                                '</div>' +
                            '</div>',
                        type: 'inline'
                    }
                });
                break;
            case 2: toastr.error(message);
                break;
            case 3:
                $.magnificPopup.open({
                    items: {
                        src:
                            '<div class="panel panel-info help-popup">' +
                                '<div class="panel-heading">' +
                                    '<h3 class="panel-title"><span class="glyphicon glyphicon-comment"></span> ' + title + '</h3>' +
                                '</div>' +
                                '<div class="panel-body">' +
                                    message +
                                '</div>' +
                            '</div>',
                        type: 'inline'
                    }
                });
                break;
        }
    }
}